# HTML Input Types

« Previous
Next Chapter »

## Input Types

This chapter describes the input types of the <input> element.

## Input Type: text

<input type="text"> defines a one-line input field for text input:

## Example

<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

First name:
Last Name:

## Input Type: password

<input type="password"> defines a password field:

## Example

<form>
User name:<br>
<input type="text" name="username">
<br>
User password:<br>
<input type="password" name="psw">
</form>
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

First name:
Password:

| The characters in a password field are masked (shown as asterisks or circles).

## Input Type: submit

<input type="submit"> defines a button for submitting form input to a form-handler.

The form-handler is typically a server page with a script for processing input data.

The form-handler is specified in the form's action attribute:

## Example

<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

First name:
Last name:

If you omit the submit button's value attribute, the button will get a default text:

## Example

<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit">
</form>
Try it Yourself »

## Input Type: radio

<input type="radio"> defines a radio button.

Radio buttons let a user select ONLY ONE of a limited number of choices:

## Example

<form>
<input type="radio" name="sex" value="male" checked>Male
<br>
<input type="radio" name="sex" value="female">Female
</form>
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

Male
Female

## Input Type: checkbox

<input type="checkbox"> defines a checkbox.

Checkboxes let a user select ZERO or MORE options of a limited number of choices.

## Example

<form>
<input type="checkbox" name="vehicle" value="Bike">I have a bike
<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form>
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

I have a bike
I have a car

## Input Type: button

<input type="button> defines a button:

## Example

<input type="button" onclick="alert('Hello World!')" value="Click Me!">
Try it Yourself »

This is how the HTML code above will be displayed in a browser:

## HTML5 Input Types

HTML5 added several new input types:

- color
- date
- datetime
- datetime-local
- email
- month
- number
- range
- search
- tel
- time
- url
- week

| Input types, not supported by old web browsers, will behave as input type text.

## Input Type: number

The <input type="number"> is used for input fields that should contain a numeric value.

You can set restrictions on the numbers.

Depending on browser support, the restrictions can apply to the input field.

## Example

<form>
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
</form>
Try it Yourself »

## Input Restrictions

Here is a list of some common input restrictions (some are new in HTML5):

Attribute | Description
--- | ---
disabled | Specifies that an input field should be disabled
max | Specifies the maximum value for an input field
maxlength | Specifies the maximum number of character for an input field
min | Specifies the minimum value for an input field
pattern | Specifies a regular expression to check the input value against
readonly | Specifies that an input field is read only (cannot be changed)
required | Specifies that an input field is required (must be filled out)
size | Specifies the width (in characters) of an input field
step | Specifies the legal number intervals for an input field
value | Specifies the default value for an input field

You will learn more about input restrictions in the next chapter.

## Example

<form>
Quantity:
<input type="number" name="points" min="0" max="100" step="10" value="30">
</form>
Try it Yourself »

## Input Type: date

The <input type="date"> is used for input fields that should contain a date.

Depending on browser support, a date picker can show up in the input field.

## Example

<form>
Birthday:
<input type="date" name="bday">
</form>
Try it Yourself »

You can add restrictions to the input:

## Example

<form>
Enter a date before 1980-01-01:
<input type="date" name="bday" max="1979-12-31"><br>
Enter a date after 2000-01-01:
<input type="date" name="bday" min="2000-01-02"><br>
</form>
Try it Yourself »

## Input Type: color

The <input type="color"> is used for input fields that should contain a color.

Depending on browser support, a color picker can show up in the input field.

## Example

<form>
Select your favorite color:
<input type="color" name="favcolor">
</form>
Try it Yourself »

## Input Type: range

The <input type="range"> is used for input fields that should contain a value within a range.

Depending on browser support, the input field can be displayed as a slider control.

## Example

<form>
<input type="range" name="points" min="0" max="10">
</form>
Try it Yourself »

You can use the following attributes to specify restrictions: min, max, step, value.

## Input Type: month

The <input type="month"> allows the user to select a month and year.

Depending on browser support, a date picker can show up in the input field.

## Example

<form>
Birthday (month and year):
<input type="month" name="bdaymonth">
</form>
Try it Yourself »

## Input Type: week

The <input type="week"> allows the user to select a week and year.

Depending on browser support, a date picker can show up in the input field.

## Example

<form>
Select a week:
<input type="week" name="week_year">
</form>
Try it Yourself »

## Input Type: time

The <input type="time"> allows the user to select a time (no time zone).

Depending on browser support, a time picker can show up in the input field.

## Example

<form>
Select a time:
<input type="time" name="usr_time">
</form>
Try it Yourself »

## Input Type: datetime

The <input type="datetime"> allows the user to select a date and time (with time zone).

Depending on browser support, a date picker can show up in the input field.

## Example

<form>
Birthday (date and time):
<input type="datetime" name="bdaytime">
</form>
Try it Yourself »

## Input Type: datetime-local

The <input type="datetime-local"> allows the user to select a date and time (no time zone).

Depending on browser support, a date picker can show up in the input field.

## Example

<form>
Birthday (date and time):
<input type="datetime-local" name="bdaytime">
</form>
Try it Yourself »

## Input Type: email

The <input type="email"> is used for input fields that should contain an e-mail address.

Depending on browser support, the e-mail address can be automatically validated when submitted.

Some smartphones recognize the email type, and adds ".com" to the keyboard to match email input.

## Example

<form>
E-mail:
<input type="email" name="email">
</form>
Try it Yourself »

## Input Type: search

The <input type="search"> is used for search fields (a search field behaves like a regular text field).

## Example

<form>
Search Google:
<input type="search" name="googlesearch">
</form>
Try it Yourself »

## Input Type: tel

The <input type="tel"> is used for input fields that should contain a telephone number.

The tel type is currently supported only in Safari 8.

## Example

<form>
Telephone:
<input type="tel" name="usrtel">
</form>
Try it Yourself »

## Input Type: url

The <input type="url"> is used for input fields that should contain a URL address.

Depending on browser support, the url field can be automatically validated when submitted

Some smartphones recognize the url type, and adds ".com" to the keyboard to match url input.

## Example

<form>
Add your homepage:
<input type="url" name="homepage">
</form>
Try it Yourself »
« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples